<?php

namespace App\Http\Controllers\Mp;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

/**
 * Class UploadController
 * @package App\Http\Controllers\Backend
 * 图片上传控制器
 */
class UploadController extends BaseController
{
    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * $width 缩略图宽度
     * $height 缩略图高度
     * 文件上传根据类型分文件夹
     * {cache}临时文件夹
     */
    public function store(Request $request)
    {
        $image = $request->file('file');
        $realPath = '/avatar';
        $url = $image->store($realPath);
        //$url = Storage::url($source);
        return response()->json([
            'message' => 'success',
            'photo' => $url,
            'url' => asset($url)
        ]);
    }
}
